package com.hua.yuan.dialog;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.TextView;
import com.hua.yuan.common.BaseDialogFragment;
import com.hua.yuan.resource.R;


/**
 * 创建时间：2017/2/6
 * 编写者：
 * 功能描述：确认取消dialog
 */

public class ConfirmCancelDialog extends BaseDialogFragment implements View.OnClickListener {
    private TextView tv_title;
    private TextView tv_confirm;
    private TextView tv_cancel;
    private String mTitle;

    @Override
    public float initDimValue() {
        return 0.6f;
    }

    @Override
    public void initOnResume() {
        setWHSize((int) (getScreenWidth(getContext()) * 0.75f), (int) (getScreenHeight(getContext())*0.24f));
    }

    @Override
    public boolean isCancel() {
        return false;
    }

    @Override
    public int gravity() {
        return 0;
    }

    @Override
    public int style() {
        return 0;
    }

    @Override
    public int initContentView() {
        return R.layout.dialog_confirm_cancel_layout;
    }

    @Override
    protected void argumentsDate() {

    }

    @Override
    public void initActionBarView(View view) {

    }

    @Override
    public void initView(View view) {
        tv_title = findView(view, R.id.tv_title);
        tv_title.setText(mTitle);
        tv_cancel = findView(view, R.id.tv_cancel);
        tv_confirm = findView(view, R.id.tv_confirm);
        tv_cancel.setOnClickListener(this);
        tv_confirm.setOnClickListener(this);
    }

    @Override
    public void initData(View view) {

    }

    @Override
    protected void initNet() {

    }


    private static FragmentManager fm;
    private static FragmentTransaction ft;
    private static ConfirmCancelDialog dialog;


    /**
     * 显示dialog
     */
    public static ConfirmCancelDialog create(FragmentManager _fm) {
        fm = _fm;
        dialog = new ConfirmCancelDialog();
        return dialog;
    }

    public void show() {
        ft = fm.beginTransaction();
        dialog.show(ft, "");
    }

    @Override
    public void onClick(View v) {
        dismiss();
        if (v == tv_confirm) {
            if (null != onConfirmListener) {
                onConfirmListener.onConfirm(v);
            }
        }
    }

    @SuppressLint("StringFormatMatches")
    public void  setMoney(String money,Context pContext) {
        String regex=pContext.getResources().getString(R.string.video_play_live_room);
        this.mTitle=String.format(regex,money);
    }

    public interface OnConfirmListener {
        void onConfirm(View v);
    }

    public OnConfirmListener onConfirmListener;

    public void setOnConfirmListener(OnConfirmListener _onConfirmListener) {
        onConfirmListener = _onConfirmListener;
    }
}
